#!/bin/sh
echo $0 $*
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}

# 修改为直接获取文件夹名称的用法,不同游戏文件名不同
GAMEDIR="/mnt/SDCARD/Ports/rvgl"
# GAMEDIR=${PWD}
echo ==========GAMEDIR is $GAMEDIR
controlfolder="../PortMaster"

source $controlfolder/control.txt
#source $controlfolder/tasksetter

get_controls

# 增加错误输出记录
exec > >(tee "$GAMEDIR/log.txt") 2>&1
cd $GAMEDIR


LIB_DIR="$GAMEDIR/lib/libarm64"

exec="rvgl.arm64"

if [ -f "first_run" ]; then
  $ESUDO cp "profiles/ark/profile.ini.$ANALOG_STICKS" "profiles/ark/profile.ini"
  $ESUDO rm "first_run"
fi

export TEXTINPUTINTERACTIVE="Y"

export LD_LIBRARY_PATH="$LIB_DIR:$LD_LIBRARY_PATH"

$ESUDO chmod 666 /dev/uinput

$GPTOKEYB "$exec" -c "./rvgl.gptk" &
"./$exec"

$ESUDO kill -9 $(pidof gptokeyb)
$ESUDO systemctl restart oga_events &
printf "\033c" >> /dev/tty1